package com.example.work4.adapter.viewHolder

import android.content.Intent
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.example.work4.ChatActivity
import com.example.work4.R
import com.example.work4.http.body.po.ChatInfoPage

class ChatViewHolder(
    var dataBinding: ViewDataBinding, var info:ChatInfoPage = ChatInfoPage(),
    val avatar: ImageView = dataBinding.root.findViewById(R.id.avatar),
    val notice: TextView = dataBinding.root.findViewById(R.id.notice)
) : RecyclerView.ViewHolder(dataBinding.root), View.OnClickListener {

    init {
        val chatCard: ConstraintLayout = dataBinding.root.findViewById(R.id.chat_card)
        chatCard.setOnClickListener(this)
    }
    override fun onClick(v: View?) {
        when(v?.id) {
            R.id.chat_card ->{
                super.itemView.context
                val intent = Intent()
                intent.putExtra("id", info.id)
                intent.putExtra("avatar", info.avatar)
                intent.putExtra("nickname", info.nickname)
                notice.visibility = View.GONE;
                intent.setClass(super.itemView.context, ChatActivity::class.java)
                super.itemView.context.startActivity(intent)
            }

        }
    }
}